<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge, chrome=1">
    <title>统计</title>
    <link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
    <link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="panel panel-info panel-content" style="overflow-y:auto;">
        <div class="panel-heading">
            <form id="statisticsForm">
                <table>
                    <tr>
                        <td>
                            <select id="type" name="type" class="form-control">
                                <option value="1">注册用户</option>
                                <option value="2">交易量</option>
                            </select>
                        </td>
                        <td class="w80">
                            <label class="center-block">统计时间</label>
                        </td>
                        <td style="width: 260px;">
                            <input type="text" id="sdate" name="sdate" placeholder="开始时间" readonly onFocus="WdatePicker({dateFmt: 'yyyy-MM', maxDate: '#F{$dp.$D(\'edate\')}', isShowClear: false})" class="form-control Wdate" style="width:120px; display: inline-block;">
                            -
                            <input type="text" id="edate" name="edate" placeholder="结束时间" readonly onFocus="WdatePicker({dateFmt: 'yyyy-MM', minDate: '#F{$dp.$D(\'sdate\')}', isShowClear: false})" class="form-control Wdate" style="width:120px; display: inline-block;">
                        </td>
                        <td>
                            <button class="btn btn-primary" type="button" onclick="statistics()">统计</button>
                        </td>
                    </tr>
                </table>
            </form>
        </div>

        <div id="viewL" style="float: left; width: 50%; height:500px;"></div>
        <div id="viewR" style="float: right; width: 50%; height:500px;"></div>
        <div style="clear: both"></div>
    </div>

    <script src="/res/common/js/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="/res/third/My97DatePicker/WdatePicker.js"></script>
    <script src="/res/common/js/moment.min.js"></script>
    <script src="/res/third/echarts/echarts.js" type="text/javascript"></script>
    <script>
        var echartL = echarts.init(document.getElementById('viewL'));
        var echartR = echarts.init(document.getElementById('viewR'));
        $(function() {
            //默认显示当年的数据
            $('#sdate').val(moment().subtract(1, 'years').format('YYYY-MM'));
            $('#edate').val(moment().format('YYYY-MM'));
            statistics();
        });

        echartL.on('click', function(param) {
            var type = $('#type').val();
            if(param.componentType == 'series') {
                $.ajax({
                    url: '/echarts/statisticsDetail.do',
                    type: 'post',
                    dataType: 'json',
                    data: { type: type, date: param.name },
                    beforeSend: function() {
                        echartR.showLoading();
                    },
                    success: function(data) {
                        if(data && data.success) {
                            echartR.setOption(JSON.parse(data.obj));
                        } else {
                            alert('获取数据失败');
                        }
                    },
                    complete: function() {
                        echartR.hideLoading();
                    }
                });
            }
        });

        function statistics() {
            $.ajax({
                url: '/echarts/statistics.do',
                type: 'post',
                dataType: 'json',
                data: $('#statisticsForm').serialize(),
                beforeSend: function() {
                    echartL.showLoading();
                },
                success: function(data) {
                    if(data && data.success) {
                        echartL.setOption(JSON.parse(data.obj));
                    } else {
                        alert('获取数据失败');
                    }
                },
                complete: function() {
                    echartL.hideLoading();
                }
            });
        }
    </script>
</body>
</html>